package com.uam.core.entity.uitls.geohash;

import com.uam.core.entity.model.GeoPoint;
import com.uam.core.entity.uitls.geohash.help.GeoHash;

/**
 * @author heguanglong
 * @description: TODO
 * @date 2022/4/1
 */
public class GeoHashUtils {

    /**
     * 获取 hash码
     * @param precision hash位数
     * @param x  经度
     * @param y  纬度
     * @return
     */
    public static String getPointHash(int precision, double x, double y) {
        GeoHash geoHash = GeoHash.withCharacterPrecision(y, x, precision);
        return geoHash.toBase32();
    }

    /**
     *
     * @param precision  hash位数
     * @param gps 经度，经度 如：114.376971,30.549608
     * @return
     */
    public static String getPointHash(int precision,String gps){
        String[] gpsArr=gps.split("\\,");
        return getPointHash(precision,Double.valueOf(gpsArr[0]),Double.valueOf(gpsArr[1]));
    }

    /**
     *
     * @param precision  hash位数
     * @param geoPoint 点信息
     * @return
     */
    public static String getPointHash(GeoPoint geoPoint, int precision){
        return getPointHash(precision,geoPoint.getX(),geoPoint.getY());
    }

}
